function yeMianShiPei(win) {
  var doc = win.document
  var docEl = doc.documentElement
  var tid
  function refreshRem() {
    var width = docEl.getBoundingClientRect().width
    if (width > 750) {
      width = 750
    }
    var rem = width / 7.5
    docEl.style.fontSize = rem + 'px'
  }
  win.addEventListener(
    'resize',
    function() {
      clearTimeout(tid)
      tid = setTimeout(refreshRem, 300)
    },
    false
  )
  win.addEventListener(
    'pageshow',
    function(e) {
      if (e.persisted) {
        clearTimeout(tid)
        tid = setTimeout(refreshRem, 300)
      }
    },
    false
  )
  refreshRem()
}
yeMianShiPei(window)

function showToast (className) {
  $(className).css('display', 'flex')
  setTimeout(function () {
    $(className).fadeOut(100)
  }, 1200)
}

function ellipsis() {
  $(function() {
    $('.ellipsis').each(function(i) {
      $('span', $(this)).css('word-break', 'break-all')
      var divH = $(this).height()
      var divW = $(this).width()
      var $span = $('span', $(this)).eq(0)
      while ($span.outerHeight() > divH) {
        $span.text(
          $span.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, '...')
        )
      }
    })
  })
}



function Contact (option) {
  option = option || {}

  this.topBackSrc = option.topBackSrc || '../images/newIndex/ppsj_fhsy_btn_icon.png'
  this.topBackHref = option.topBackHref || 'http://m.10pinpaiwang.com/skin/default/common/image/tpy_fx_icon.png'

  this.goTopSrc = option.goTopSrc || 'http://m.10pinpaiwang.com/skin/default/common/image/tpy_fx_icon.png'

  this.backVoteSrc = option.backVoteSrc || '../images/newIndex/home_fhtp_btn_icon.png'
  this.backVoreHref = option.backVoreHref || 'http://m.10pinpaiwang.com/skin/default/common/image/tpy_fx_icon.png'
}
var contactArr = {
  addContact: function() {
    var dom = null
    if (!$('.contact').length) {
      dom = "<div class=\"contact\"></div>"
      $('body').append(dom)
    }
  },
  addGoTop: function  (option) {
    option = option || {}
    var hide = option['hide'] || false
    var imgSrc =  option['src'] || this.goTopSrc
    if (hide) return $('.contact .goTop').hide()
    this.addContact()
    var timer = null
    var dom =
    "    <div class=\"common\">"+
    "      <img class=\"goTop\" src=" + imgSrc + ">"+
    "    </div>"
    if (!$('.contact .goTop').length) $('.contact').append(dom)
    var goTop = $('.contact .goTop')
    if ($(window).scrollTop() <= 0) goTop.css('display', 'none')
    $(window).scroll(function () {
      // console.log($(this).scrollTop())
      if (timer) clearTimeout(timer)
      timer = setTimeout(function () {
        if ($(this).scrollTop() > 30) goTop.css('display', 'flex')
        else goTop.fadeOut(122)
      }, 133)
    })
    $('.goTop').on('click', function () {
      $('html,body .content').animate({
        scrollTop: 0
      }, 222)
      $('html,body').animate({
        scrollTop: 0
      }, 222)
    })
  },
  addBackVote: function (option) {
    option = option || {}
    var hide = option['hide'] || false
    var imgSrc =  option['src'] || this.backVoteSrc
    var href = option['href'] || this.backVoreHref
    var backVote = $('.contact .backVote')
    if (hide) return backVote.hide()
    this.addContact()
    var dom =
    "    <div class=\"common\">"+
    "      <img class=\"backVote\" src=" + imgSrc + ">"+
    "    </div>"
    if (!$('.contact .backVote').length) $('.contact').append(dom)
    $('.backVote').on('click', function () {
      window.location.href = href
    })
  },
  addTopBack: function (option) {
    option = option || {}
    var hide = option['hide'] || false
    var imgSrc = option['src'] || this.topBackSrc
    var href = option['href'] || this.topBackHref
    if (hide) return $('.topBack').hide()
    var dom = "<img class='topBack' src=" + imgSrc + ">"
    if (!$('topBack').length) $('.container').append(dom)
    var topBack = $('.topBack')
    if ($(window).scrollTop() > 0) topBack.css('top',  ($(window).scrollTop() + topBack[0].offsetTop) + 'px')
    var offsetTop = topBack[0].offsetTop - $(window).scrollTop()
    $(window).scroll(function () {
      topBack.css('top', ($(this).scrollTop() + offsetTop) + 'px')
    })
    topBack.on('click', function () {
      window.location.href = href
    })
  }
}
for (var i in contactArr) {
  Contact.prototype[i] = contactArr[i]
}
